const Koa = require('koa')
const router = require('koa-router')()
const views = require('koa-views')
const ejs = require('ejs')
const common = require('./module/common')


const app = new Koa()

app.use(views('views', {
  extension: 'ejs'
}))


//配置路由
router.get('/', async (ctx) => {
  await ctx.render('index')
})
// 接收post提交的数据
router.post('/doAdd', async (ctx) => {
  // 原生nodejs在koa中获取表单提交的数据
  const data = await common.getPostData(ctx)
  console.log(data)
  ctx.body = data
})


//启动路由
app.use(router.routes())
app.use(router.allowedMethods())

app.listen(3000)